/*
 * Copyright (C) 2003,2004 Christopher J. Stawarz <cstawarz@cfa.harvard.edu>
 *
 * This file is part of SLglade.
 *
 * SLglade is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * SLglade is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SLglade; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include <stdlib.h>
#include <unistd.h>
#include <slang.h>
#include <glade/glade.h>

#define  SLIRP_VERSION 1.0.5

#include "glade_types.h"


/*
 * Intrinsic constants and variables
 */

/* SLGLADE_VERSION_STRING, SLGLADE_VERSION_NUMBER, and
 * SLGLADE_DOC_DIR are defined at compile time */

static char *slglade_version_string = SLGLADE_VERSION_STRING;
static char *slglade_doc_dir = SLGLADE_DOC_DIR;

static SLang_IConstant_Type glade_IConsts[] = 
{
  MAKE_ICONSTANT("_glade_module_version", SLGLADE_VERSION_NUMBER),
  SLANG_END_ICONST_TABLE
};

static SLang_Intrin_Var_Type glade_IVars[] =
{
  MAKE_VARIABLE("_glade_module_version_string", &slglade_version_string,
    SLANG_STRING_TYPE, 1),
  MAKE_VARIABLE("_glade_module_doc_dir", &slglade_doc_dir,
    SLANG_STRING_TYPE, 1),
  SLANG_END_INTRIN_VAR_TABLE
};


/*
 * Intrinsic functions
 */

#include "glade_init.h"
#include "glade_glue.c"
#include "glade_types.c"

static SLang_Intrin_Fun_Type glade_Intrin_Funcs[] =
{
  MAKE_INTRINSIC_0("glade_require",slglade_require,V),
  MAKE_INTRINSIC_0("glade_xml_new",slglade_xml_new,V),
  MAKE_INTRINSIC_0("glade_xml_new_from_buffer",slglade_xml_new_from_buffer,V),
  MAKE_INTRINSIC_0("glade_xml_signal_connect",slglade_xml_signal_connect,V),
  MAKE_INTRINSIC_0("glade_xml_signal_autoconnect",slglade_xml_signal_autoconnect,V),
  MAKE_INTRINSIC_0("glade_xml_get_widget",slglade_xml_get_widget,V),
  MAKE_INTRINSIC_0("glade_xml_get_widget_prefix",slglade_xml_get_widget_prefix,V),
  MAKE_INTRINSIC_0("glade_get_widget_name",slglade_get_widget_name,V),
  MAKE_INTRINSIC_0("glade_get_widget_tree",slglade_get_widget_tree,V),
  SLANG_END_INTRIN_FUN_TABLE
};


/*
 * Module initialization
 */

SLANG_MODULE(glade);
int init_glade_module_ns(char *ns_name)
{
   SLang_NameSpace_Type *ns = NULL;

   /* Before doing anything, check that SLgtk has been loaded */
   if (-1 != SLang_is_defined("_slgtk_version_string")) {
	SLang_verror(SL_INTRINSIC_ERROR,"gtk module has not been loaded");
        return -1;
   }

   if (ns_name != NULL) {
	ns = SLns_create_namespace (ns_name);
	if (ns == NULL)
	   return -1;
   }

   slirp_debug_pause("glade");

   allocate_builtin_opaque_types();

   if (allocate_glade_opaque_types() == -1)
        return -1;

   patch_glade_ftable(glade_Intrin_Funcs);

   if (-1 == SLns_add_iconstant_table (ns, glade_IConsts, NULL))
	return -1;

   if (-1 == SLns_add_intrin_var_table (ns, glade_IVars, NULL))
	return -1;

   if (-1 == SLns_add_intrin_fun_table (ns, glade_Intrin_Funcs,"__glade__"))
	return -1;

   return 0;
}

